package ua.kratik.seabattle.game;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdmiralsFleet {
	
	private static Logger logger = LoggerFactory.getLogger(AdmiralsFleet.class);
	
	List<Ship> ships;
	
	int aliveShipsCount;
	
	public AdmiralsFleet(List<ua.kratik.seabattle.domain.Fleet> fleetBeanList){
		Iterator<ua.kratik.seabattle.domain.Fleet> it;
		ua.kratik.seabattle.domain.Fleet item;
		it = fleetBeanList.iterator();
		logger.debug("Creating ships...");
		Ship ship;
		ships = new ArrayList<Ship>();
		while(it.hasNext()){
			item = it.next();
			for(int i=0; i < item.getShipsCount(); i++){
				ship = new Ship(item.getShip());
				ships.add(ship);
				logger.trace("Ship added: " + ship.getShipBean().getName());
			}
		}
		aliveShipsCount = ships.size();
		logger.debug("All ships were created. Count = " + aliveShipsCount);
	}



	public List<Ship> getShips() {
		return ships;
	}
	
	/**
	 * 
	 * @return decreased ships count
	 */
	public int decreaseAliveShipsCount(){
		logger.debug("Ships count decreased to = " + (aliveShipsCount - 1));
		return --aliveShipsCount;
	}

	public int getAliveShipsCount() {
		return aliveShipsCount;
	}
}
